module.exports   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 140

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 140
rs 8.2857

10 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
A 0 3 1
A 0 3 1
A 0 3 1
A 0 14 3
A 0 11 2
A 0 3 1
A 0 4 1
A 0 4 1
A 0 4 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
module.exports = function(GedcomX){
2
3
  var utils = require('../utils'),
4
      AtomCommon = require('./AtomCommon');
5
  
6
  /**
7
   * The agent used to generate a feed
8
   * 
9
   * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec}
10
   * @see {@link https://tools.ietf.org/html/rfc4287#section-4.2.4|RFC 4287}
11
   * 
12
   * @class AtomGenerator
13
   * @extends AtomCommon
14
   * @param {Object} [json]
15
   */
16
  var AtomGenerator = function(json){
17
    
18
    // Protect against forgetting the new keyword when calling the constructor
19
    if(!(this instanceof AtomGenerator)){
20
      return new AtomGenerator(json);
21
    }
22
    
23
    // If the given object is already an instance then just return it. DON'T copy it.
24
    if(AtomGenerator.isInstance(json)){
25
      return json;
26
    }
27
    
28
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
  };
30
  
31
  AtomGenerator.prototype = Object.create(AtomCommon.prototype);
32
  
33
  AtomGenerator._gedxClass = AtomGenerator.prototype._gedxClass = 'GedcomX.AtomGenerator';
34
  
35
  AtomGenerator.jsonProps = [
36
    'uri',
37
    'version',
38
    'value'
39
  ];
40
  
41
  /**
42
   * Check whether the given object is an instance of this class.
43
   * 
44
   * @param {Object} obj
45
   * @returns {Boolean}
46
   */
47
  AtomGenerator.isInstance = function(obj){
48
    return utils.isInstance(obj, this._gedxClass);
49
  };
50
51
  /**
52
   * Initialize from JSON
53
   * 
54
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
55
   * @return {AtomGenerator} this
56
   */
57
  AtomGenerator.prototype.init = function(json){
58
    
59
    AtomCommon.prototype.init.call(this, json);
60
    
61
    if(json){
62
      this.setUri(json.uri);
63
      this.setVersion(json.version);
64
      this.setValue(json.value);
65
    }
66
    return this;
67
  };
68
  
69
  /**
70
   * Set the uri
71
   * 
72
   * @param {String} uri
73
   * @return {AtomGenerator} this
74
   */
75
  AtomGenerator.prototype.setUri = function(uri){
76
    this.uri = uri;
77
    return this;
78
  };
79
  
80
  /**
81
   * Get the uri
82
   * 
83
   * @return {String} this
84
   */
85
  AtomGenerator.prototype.getUri = function(){
86
    return this.uri;
87
  };
88
  
89
  /**
90
   * Set the version
91
   * 
92
   * @param {String} version
93
   * @return {AtomGenerator} this
94
   */
95
  AtomGenerator.prototype.setVersion = function(version){
96
    this.version = version;
97
    return this;
98
  };
99
  
100
  /**
101
   * Get the version
102
   * 
103
   * @return {String} this
104
   */
105
  AtomGenerator.prototype.getVersion = function(){
106
    return this.version;
107
  };
108
  
109
  /**
110
   * Set the value
111
   * 
112
   * @param {String} value
113
   * @return {AtomGenerator} this
114
   */
115
  AtomGenerator.prototype.setValue = function(value){
116
    this.value = value;
117
    return this;
118
  };
119
  
120
  /**
121
   * Get the value
122
   * 
123
   * @return {String} this
124
   */
125
  AtomGenerator.prototype.getValue = function(){
126
    return this.value;
127
  };
128
  
129
  /**
130
   * Export the object as JSON
131
   * 
132
   * @return {Object} JSON object
133
   */
134
  AtomGenerator.prototype.toJSON = function(){
135
    return this._toJSON(AtomCommon, AtomGenerator.jsonProps);
136
  };
137
  
138
  GedcomX.AtomGenerator = AtomGenerator;
139
140
};